<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <script type="text/javascript" src="../../inc/ctx.jsp"></script>
        <script type="text/javascript" src="../js/g.js"></script>
        <script type="text/javascript" src="http://cdn.uuola.cn/js/formvalid.js" charset="utf-8"></script>
        <script type="text/javascript" src="http://cdn.uuola.cn/js/jq.md5.js" charset="utf-8"></script>
        <link href="../css/com.css" type="text/css" rel="stylesheet"/>
        <style>
            #panel{width:90%;}
        </style>
    </head>
    <body>

        <div id="panel">
            <form id="mgr_add_frm" name="mgr_add_frm">
                <table>
                    <tr>
                        <th colspan="3">&nbsp;添加管理员</th>
                    </tr>
                    <tr>
                        <td width="21%"  class="r">管理员账号：</td>
                        <td width="33%">
                            <input name="mgrname" type="text" id="mgrname" tabindex="1" style="width:200px;" maxlength="16" valid="required|custom" custom="MAD.checkName" errmsg="管理员账号不能为空!|账号名称已经存在,请重新设置." />*</td>
                        <td width="46%"><div id="err_mgrname"></div></td>
                    </tr>
                    <tr>
                        <td  class="r">登录密码：</td>
                        <td><input name="mgrkey" type="text" id="mgrkey" tabindex="2" style="width:200px;" maxlength="20" valid="required" errmsg="管理员密码不能为空!" />
                            *</td>
                        <td><div id="err_mgrkey"></div></td>
                    </tr>
                    <tr>
                        <td  class="r">管理员角色：</td>
                        <td>
                            <select name="roleid" id="roleid"></select>
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td class="c">&nbsp;
                            <input name="submitBtn" type="button" class="button medium orange" id="submitBtn" tabindex="7" value="添加" onClick="MAD.submit();" /></td>
                        <td></td>
                    </tr>
                </table>
            </form>
        </div>
        <script type="text/javascript">
            var frm = ut.e('mgr_add_frm');
            initValid(frm);
            var MAD={
                checkName:function(inp){
                    var r=null;
                    if(!va.nick(inp.value)){ut.m('账户名不符合要求. 请重新设置.');return false;}
                    $.ajax({type:"GET", url:"../app/admin/is_repeat_name.shtm?r="+ut.r()+'&mgrname='+inp.value, dataType:"text",async:false,success:function (msg){
                            r = $.trim(msg);
                        }}); 
                    if (r=='true') {
                        return false;
                    } else {
                        return true;
                    }
                },
                submit:function(){
                    if(va.isnull($('#roleid').val())){ut.m('请选择角色.');return;} 
                    var $rb=$('#submitBtn');
                    if(validator(frm)){
                        $rb.attr('disabled','disabled');
                        $('#mgrkey').val($.md5($('#mgrkey').val()));
                        $.get('../app/admin/make_mgr.shtm',$('#mgr_add_frm').serialize(),function(x){
                            var r = $.trim(x);
                            if(r=='ok'){
                                ut.m('新建管理员成功!');
                                ut.reload('?'+ut.r());
                            }else{
                                ut.m('操作失败.!'+r);
                                frm.reset();
                                $rb.removeAttr('disabled');
                            }
                        });
                    }   
                }
            }; 

            MGR.loadRoleSel();
        </script>
    </body>
</html>
